import request from '../../utils/request'


/**
 * 查询汇率列表
 * @param code
 * @param name
 * @param status
 * @param page
 * @returns {Promise.<Object>}
 */
export async function querCurrencyRateList({code, name,  beginTime, endTime,status ,page}) {
    return request(apiPath.basedata + "/api/currencyRate", {
        method: 'get',
        data: { code, name,  beginTime, endTime, status , page: page.page, size: page.size}
    });
}

/**
 * 增加汇率
 * @param code
 * @param name
 * @param status
 * @param page
 * @returns {Promise.<Object>}
 *
 */
export async function addCurrencyRate({code, name, targetcurrency, status, rate,  userId,ratetime}) {
    userId = 1;
    let creator = userId;
    return request(apiPath.basedata + "/api/currencyRate", {
        method: 'post',
        data: { code, name, targetcurrency, status, rate, userId,ratetime, creator}
    });
}

export async function uploadCurrencyRate({fileUrl}) {
    return request(apiPath.basedata+"/api/currencyRateUpload",{
        method:'post',
        data:{fileUrl},
    })

}

/**
 * 删除汇率
 * @param id
 * @returns {Promise.<Object>}
 */
export async function deleteCurrencyRate({id}) {
    return request(apiPath.basedata + "/api/currencyRate/"+ id, {
        method: 'delete',
    });
}

/**
 * 查找汇率
 * @param id
 * @returns {Promise.<Object>}
 */
export async function getCurrencyRateById({id}) {
    return request(apiPath.basedata + "/api/currencyRate/" + id, {
        method: 'get'
    });
}

/**
 * 修改汇率
 * @param code
 * @param name
 * @param targetcurrency
 * @param userId
 * @param rate
 * @param status
 * @returns {Promise.<Object>}
 */
export async function updateCurrencyRate({id, code, name, targetcurrency, userId, rate, status,ratetime}) {
    userId = 1;
    status = 1;
    let updater = userId;
    return request(apiPath.basedata + "/api/currencyRate", {
        method: 'put',
        data: { id, code, name, targetcurrency, userId, rate, status, ratetime, updater}
    });
}

/**
 * 同步外管局月初汇率
 */
export async function synchronizeCurrencyRate() {
    return request(apiPath.basedata + "/api/currencyRate/synchronize", {
        method: 'get',
    });
}

